<template>
  <section class="index" id="index">
    <div class="watermask"></div>
    <nav-index v-if="showNav" @cliclSearchImg="cliclSearchImg" @changeShow="changeShow"></nav-index>
    <search
      v-show="nowShow=='search'"
      :search_change="search_change"
      :searchInput="search_input"
      @emitRes="emitRes"
      class="water_mark"
    ></search>
    <analyse
      v-show="nowShow=='analyse'"
      :analyse_change="analyse_change"
      :searchInput="analyse_input"
      class="water_mark"
    ></analyse>
    <!--<analyse v-show="nowShow=='analyse'" :searchInput="search_input" :res="res"></analyse>-->
  </section>
</template>

<script>
import navIndex from "@/components/nav";
import search from "@/pages/search";
import analyse from "@/pages/analyse";
import { watermark } from "@/components/tools";
import { getWatermarka, apiGetConfig } from "@/components/api";
export default {
  components: {
    navIndex,
    search,
    analyse
  },
  data() {
    return {
      nowShow: "analyse",
      search_input: "",
      analyse_input: "",
      res: {},
      token: "",
      watermarkStr: "",
      search_change: false,
      showNav: false,
      analyse_change: false
    };
  },
  methods: {
    cliclSearchImg(val) {
      if (this.nowShow == "analyse") {
        this.analyse_change = !this.analyse_change;
        this.analyse_input = val.trim();
      } else if (this.nowShow == "search") {
        this.search_change = !this.search_change;
        this.search_input = val.trim();
      }
    },
    changeShow(val) {
      this.nowShow = val;
    },
    emitRes(res) {
      this.res = res;
    },
    urlDel(name) {
      var loca = window.location;
      console.log(loca);
      var baseUrl = loca.origin + loca.hash;
      console.log(baseUrl);
      return baseUrl;
      //					    var query = loca.search;/*删去#/?*/
      //					      console.log(query)
      //					    if (query.indexOf(name)>-1) {
      //					        var obj = {}
      //					        var arr = query.split("&");
      //					        for (var i = 0; i < arr.length; i++) {
      //					            arr[i] = arr[i].split("=");
      //					            obj[arr[i][0]] = arr[i][1];
      //					        };
      //					        delete obj[name];
      //					        console.log(obj)
      //					        var url = baseUrl + JSON.stringify(obj).replace(/[\"\{\}]/g,"").replace(/\:/g,"=").replace(/\,/g,"&");
      //					        return url
      //						}
    },
    watermarka() {
      watermark(this.watermarkStr, "#index");
    }
  },
  created() {
    //      		this.watermarka();
    //      		console.log('01_10第二版')
    //				console.log(this.$route);
    //				 var loca = window.location;
    //					   console.log(loca)
    //				if(loca.search.indexOf('token')!=-1){
    //					this.token =loca.search.substr(loca.search.indexOf('token'),loca.search.length)
    //					sessionStorage.setItem('token',this.token.split('=')[1]);
    //					window.location.replace(this.urlDel('token'))
    //				}
    //				this.$nextTick(()=>{/*行的DOM操作一定要放在方法里*/
    //	        	 	console.log('水印出现');
    //	        	 	getWatermarka(this);
    //	        	})
    apiGetConfig(this);
    //				getWatermarka(this);
  },
  mounted() {
    getWatermarka(this);
  },
  updated() {
    //  			this.$nextTick(()=>{/*行的DOM操作一定要放在方法里*/
    //	        	 	console.log('dwadw');
    //	        	 	this.watermarka();
    //	        	})
    this.watermarka();
  }
};
</script>

<style>
</style>